package pers.gxm.javaweb;

import java.io.IOException;
import java.io.InputStream;

public class MyHttpRequest {
    private InputStream is;
    public MyHttpRequest(InputStream is){
        this.is = is;
    }

    /**
     * 读取请求内容转换为字符串
     * @return
     */
    public String parse(){
        byte[] bytes = new byte[1024];
        try {
            is.read(bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return new String(bytes);
    }

    public String getPath(String url){
        int left = url.indexOf(" ");
        int right = url.indexOf(" ", left + 1);
        return url.substring(left + 1, right);
    }
}
